<template>
    <div class="culturePlanTemplate" style="padding-left:10px;">
        <el-row>
            <el-col>
                <div class="item-group">
                    <label class="secondary-text label">审批类型：</label>
                    <div class="display-inline-block">
                        <span class="majoy-text span">培养计划
                        </span>
                    </div>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <el-col>
                <div class="item-group">
                    <label class="secondary-text label">审批内容：</label>
                    <div class="display-inline-block">
                        <span class="majoy-text span" style="text-decoration:underline;cursor:pointer"  @click="showCulturePlan">{{major}}{{$t("culturePlan.culturePlan")}}
                        </span>
                    </div>
                </div>
            </el-col>
        </el-row>
        <!--个人培养计划-->
        <el-dialog title="个人培养计划" width="80%" :visible.sync="showCulturePlanDialog" :close-on-click-modal="false"
            :close-on-press-escape="false">
            <personPlanDetail v-if="content.projId == 2 || content.projId == 4" :student-id='approvalInfo.uid' :approveDetail='approveDetail' read-only=true />
            <updataMyTraningPlan v-if="content.projId == 1" :studentID='approvalInfo.uid' :schemeID='content.cultureId' />
        </el-dialog>
    </div>
</template>
<script>
import personPlanDetail from '../../culture/plan/personalPlanDetail';
import updataMyTraningPlan from '../../ugdCulturePlan/planApproval/updataMyTraningPlan';
import {selectApproFlow} from "common/src/api/approval";
import { findUserInfoByIdType, findLocalUserById } from "common/src/api/user";
export default {
    components: {
        personPlanDetail,
        updataMyTraningPlan
    },
    props: {
        content: {
            default: null,
        },
    },
    data(){
        return {
            id: '', //编号
            cultureName: '', //培养方案名称
            showCulturePlanDialog: false,
            major:'',
            approveDetail:true,
            approvalInfo: {
                uid: ''
            },
        }
    },
    mounted (){
        this.id = this.$route.query.id;
        this.initPage(this.id);
    },
    methods: {
        showCulturePlan(){
            this.showCulturePlanDialog=true;
        },
        initPage(id) {
            selectApproFlow(id).then(res => {
                if (res && res.data) {
                const _user = {
                    uid: res.data.applicantId,
                    type: res.data.userType ? res.data.userType : "2"
                };

                if (res.data.userType === "3") {
                    this._initLocalUser(_user.uid);
                } else {
                    this._init_(_user);
                }
                this.approvalInfo.uid=res.data.applicantId;
                this.approvalInfo.no = res.data.no;
                this.approvalInfo.time=res.data.time;
                let result=JSON.parse(res.data.content);
                if(result&&result.cultureName){
                    this.cultureName=result.cultureName;
                }
                if(result&&result.departmentId){
                    this.departmentName=result.departmentId;
                }
                 if(result&&result.major){
                    this.major=result.major;
                }
                this.rollInfo = res.data;
                }
            });
        },
        _init_(user) {
        const query = "userId=" + user.uid + "&type=" + user.type;
        findUserInfoByIdType(query).then(res => {
            if (res.code === 200 && res.data) {
            res.data.userType = user.type;
            this.user = res.data;
            }
        });
        },
        _initLocalUser(uid) {
        findLocalUserById("userId=" + uid).then(res => {
            if (res.code === 200 && res.data) {
            this.user = res.data;
            this.user.name = res.data.userName;
            }
        });
        },
    } 
}
</script>

